//引入mock模块
import Mock from 'mockjs';

//返回注册的请求
Mock.mock('/api/post/register', 'post', () => {
    return {
        status: 20000,
        message: '注册成功'
    }
})

//返回登陆的请求
Mock.mock('/api/post/login', 'post', (options) => {
    let body = JSON.parse(options.body)
    return {
        status: 20000,
        message: "登陆成功",
        email: body.email,
        pass: body.pass,
    }
})

//返回对点的请求
Mock.mock('/api/2backcode/point/findall', 'get', () => {
    let data = [
        {
            "pointId": 1,
            "pointName": "计算机网络知识汇总"
        },
        {
            "pointId": 10,
            "pointName": "组网"
        },
        {
            "pointId": 100,
            "pointName": "网络设备配置基础"
        },
        {
            "pointId": 1000,
            "pointName": "管理端口"
        },
        {
            "pointId": 1001,
            "pointName": "管理方式"
        },
        {
            "pointId": 1002,
            "pointName": "IOS与CLI"
        },
        {
            "pointId": 1003,
            "pointName": "文件备份与恢复"
        },
        {
            "pointId": 1004,
            "pointName": "口令恢复"
        },
        {
            "pointId": 10000,
            "pointName": "IOS"
        },
        {
            "pointId": 10001,
            "pointName": "CLI"
        },
        {
            "pointId": 10002,
            "pointName": "存储部件"
        },
        {
            "pointId": 10003,
            "pointName": "配置文件的备份与恢复"
        },
        {
            "pointId": 10004,
            "pointName": "映像文件的备份、恢复与升级"
        }
    ]
    return {
        data: data
    }
})

//返回对边的请求
Mock.mock('/api/2backcode/edge/findall', 'get', () => {
    let data = [
        {
            beforeId: "1",
            afterId: "10"
        },
        {
            beforeId: "10",
            afterId: "100"
        },
        {
            beforeId: "100",
            afterId: "1000"
        },
        {
            beforeId: "100",
            afterId: "1001"
        },
        {
            beforeId: "100",
            afterId: "1002"
        },
        {
            beforeId: "100",
            afterId: "1003"
        },
        {
            beforeId: "100",
            afterId: "1004"
        },
        {
            beforeId: "1002",
            afterId: "10000"
        },
        {
            beforeId: "1002",
            afterId: "10001"
        },
        {
            beforeId: "1003",
            afterId: "10002"
        },
        {
            beforeId: "1003",
            afterId: "10003"
        },
        {
            beforeId: "1003",
            afterId: "10004"
        },
        {
            beforeId: "1000",
            afterId: "-1"
        },
        {
            beforeId: "1001",
            afterId: "-1"
        },
        {
            beforeId: "10000",
            afterId: "-1"
        },
        {
            beforeId: "10001",
            afterId: "-1"
        },
        {
            beforeId: "10002",
            afterId: "-1"
        },
        {
            beforeId: "10003",
            afterId: "-1"
        },
        {
            beforeId: "10004",
            afterId: "-1"
        },
        {
            beforeId: "1004",
            afterId: "-1"
        },

    ]
    return {
        data: data
    }
})

//拦截上传文件请求
Mock.mock('/api/2backcode/address/uploadFile', 'post', (options) => {
    console.log(options.body)
    console.log(options.body.get('file'))
})

//请求评论区
Mock.mock('/api/2backcode/comment/findall', 'get', () => {
    let data = [
        {
            "id": 1,
            "title": "测试1号",
            "text": "这是测试1号"
        },
        {
            "id": 2,
            "title": "测试2号",
            "text": "这是测试2号"
        },
        {
            "id": 3,
            "title": "测试3号",
            "text": "这是测试3号"
        },
    ]
    return {
        data: data
    }
})

//上传评论
Mock.mock('/api/2backcode/comment/upload', 'post', (options) => {
    let body = JSON.parse(options.body)
    console.log(body)
    return {
        status: 20000,
        title: body.params.title,
        text: body.params.text,
    }
})

//请求详细评论
Mock.mock('/api/2backcode/post/findall', 'post', (options) => {
    let body = JSON.parse(options.body)
    let data = [
        {
            "post": "我来评论了"
        },
        {
            "post": "我是评论区测试员"
        }
    ]
    return {
        title: body.params.title,
        data: data,
    }
})

//发表详细评论
Mock.mock('/api/2backcode/post/add', 'post', (options) => {
    let body = JSON.parse(options.body)
    return {
        message: body.params.message,
        status: 20000
    }
})